package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Ticket;
import cn.wolfcode.trip.base.mapper.TicketMapper;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.ITicketService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TicketServiceImpl implements ITicketService {

    @Autowired
    private TicketMapper ticketMapper;

    public PageInfo<Ticket> query(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(), qo.getPageSize());
        List<Ticket> list = ticketMapper.selectForList(qo);
        return new PageInfo(list);
    }

    public void saveOrUpdate(Ticket ticket) {
        if (ticket.getId() != null) {
            ticketMapper.updateByPrimaryKey(ticket);
        } else {
            ticketMapper.insert(ticket);
        }
    }

    public void delete(Long id) {
        ticketMapper.deleteByPrimaryKey(id);
    }

}
